import {GET, POST, PUT, DELETE, path} from './config';
import {request, requestJson, requestDelete, requestPut} from './core';

const network = {
  // ==================== 用户模块 ====================
  login(params){
    return requestJson(POST, path.login, params)
  },
  register(params){
    return requestJson(POST, path.register, params)
  },
  getUserInfo(){
    return request(GET, path.getUserInfo)
  },
  updateUser(params){
    return requestJson(PUT, path.updateUser, params)
  },
  getUserBaseCount(){
    return request(GET, path.getUserBaseCount)
  },

  // ==================== 房源模块 ====================
  getHouseList(params){
    return request(GET, path.getHouseList, {params})
  },
  pendingHouseList(params){
    return request(GET, path.pendingHouseList, {params})
  },
  publishHouse(data){
    return requestJson(POST, path.publishHouse, data)
  },
  updateHouse(data){
    return requestJson(PUT, path.updateHouse, data)
  },
  deleteHouseById(id){
    return requestDelete(DELETE, path.deleteHouse + id)
  },
  getHouseDetail(id){
    return request(GET, path.getHouseDetail + id)
  },
  searchHouse(params){
    return request(GET, path.searchHouse, {params})
  },
  findHouseByRole(params){
    return requestJson(POST, path.findHouseByRole, params)
  },
  auditHouse(data){
    return requestJson(PUT, path.auditHouse, data)
  },

  // ==================== 预约模块 ====================
  createAppointment(data){
    return requestJson(POST, path.createAppointment, data)
  },
  getMyAppointments(params){
    return requestJson(POST, path.getMyAppointments, params)
  },
  getLandlordAppointments(params){
    return requestJson(POST, path.getLandlordAppointments, params)
  },
  handleAppointment(data){
    return requestJson(PUT, path.handleAppointment, data)
  },
  cancelAppointment(data){
    return requestJson(PUT, path.cancelAppointment, data)
  },
  getAppointmentDetail(id){
    return request(GET, path.getAppointmentDetail + id)
  },

  // ==================== 申请模块 ====================
  createApply(data){
    return requestJson(POST, path.createApply, data)
  },
  getMyApplies(params){
    return requestJson(POST, path.getMyApplies, params)
  },
  getLandlordApplies(params){
    return requestJson(POST, path.getLandlordApplies, params)
  },
  handleApply(data){
    return requestJson(PUT, path.handleApply, data)
  },
  cancelApply(data){
    return requestJson(PUT, path.cancelApply, data)
  },
  getApplyDetail(id){
    return request(GET, path.getApplyDetail + id)
  },

  // ==================== 收藏模块 ====================
  addCollection(data){
    return requestJson(POST, path.addCollection, data)
  },
  removeCollection(houseId){
    return requestDelete(DELETE, path.removeCollection + houseId)
  },
  checkCollection(houseId){
    return request(GET, path.checkCollection + houseId)
  },
  getMyCollections(params){
    return requestJson(POST, path.getMyCollections, params)
  },

  // ==================== 消息模块 ====================
  getMessageList(params){
    return requestJson(POST, path.getMessageList, params)
  },
  readMessage(id){
    return requestPut(PUT, path.readMessage + id)
  },
  readMessageBatch(data){
    return requestJson(PUT, path.readMessageBatch, data)
  },
  getUnreadCount(){
    return request(GET, path.getUnreadCount)
  },
  deleteMessage(id){
    return requestDelete(DELETE, path.deleteMessage + id)
  },
  getMessageDetail(id){
    return request(GET, path.getMessageDetail + id)
  },
};
//抛出network
export default network;

